package acme.ws;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class HeaderServlet extends JSONServlet{

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {

		List<Header> headers = new ArrayList<HeaderServlet.Header>();

		Enumeration<String> names = req.getHeaderNames();
		while(names.hasMoreElements()){
			Header h = new Header();
			h.name = names.nextElement();
			h.value = req.getHeader(h.name);
			headers.add(h);
		}
		
		returnJSON(headers, resp);
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doPost(req, resp);
	}
	
	private static class Header{
		String name = null;
		String value = null;
	}

}